package com.gxwy.jiaoyi.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.gxwy.jiaoyi.form.JiaoYi;

@Repository
public class JiaoYiDaoImpl implements JiaoYiDao {

	@Autowired
	private SessionFactory sessionFactory;
	
	
	public void add(JiaoYi jy) {
		sessionFactory.getCurrentSession().save(jy);

	}
	
	public JiaoYi findById(Integer id) {
		return (JiaoYi) sessionFactory.getCurrentSession().createQuery("from JiaoYi j where j.id=?").setInteger(0, id).uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<JiaoYi> chaxunmingxi(String zh, String qsrq, String jzrq) {
		return sessionFactory.getCurrentSession().createQuery("from JiaoYi where zhuanchuzhanghu=? and jiaoyishijian between ? and ?")
				.setString(0, zh).setString(1,qsrq).setString(2,jzrq).list();
	}

	public String findHuiDan() {
		return (String) sessionFactory.getCurrentSession().createQuery("select max(huidanhao) from JiaoYi").uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<JiaoYi> chaxunjiaoyimingxi(String yhzh, String qsrq, String jzrq) {
		return sessionFactory.getCurrentSession().createQuery("from JiaoYi where (zhuanchuzhanghu=? and zhuanruzhuanchu='0' or zhuanruzhanghu=? and zhuanruzhuanchu='1') "
				+ "and jiaoyishijian between ? and ?").setString(0, yhzh).setString(1,yhzh).setString(2,qsrq).setString(3,jzrq).list();
	}

}
